package br.com.localfloripa.dao;

import java.util.List;

import javax.inject.Named;
import javax.persistence.Query;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.com.localfloripa.entities.Endereco;

@Named("enderecoDao")
public class EnderecoDao extends DaoManager<Endereco> {
	
	private static final Logger log = LoggerFactory.getLogger(EnderecoDao.class);

	public EnderecoDao() {
		super();		
	}

	@Override
	public Endereco findById(Long id) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	public List<Endereco> listEnderecoPaged(int pagina, int max) throws Exception {
		
		Query query = em.createQuery("SELECT e FROM Endereco e");
		query.setFirstResult(pagina);
		query.setMaxResults(max);
		return query.getResultList();		
	}
	
	public Long countEnderecos() throws Exception {		
		Query query = em.createQuery("SELECT COUNT(e.id) FROM Endereco e WHERE (e.latitude IS NULL AND e.longitude IS NULL)");
		return (Long) query.getSingleResult();
		
	}
	
	

}
